import React, { Component } from 'react';
import emitter from './events';

class Box extends Component {
  constructor (props) {
    super(props);
    this.state = {
      background: 'orange'
    };
  }
  componentDidMount () {
    this.changeColor = emitter.on('changeColor', arg => {
      console.log(arg);
      this.setState({background: arg})
    });
  }
  componentWillUnmount () {
    // this.changeColor
    emitter.removeListener(this.changeColor);
  }
  render() {
    return (
      <div style={{background: this.state.background, width: 100, height: 100}}></div>
    );
  }

}

export default Box;
